package org.sdp.pearproject.service.impl;


import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import org.sdp.pearproject.dto.request.*;
import org.sdp.pearproject.dto.response.*;
import org.sdp.pearproject.dao.domain.*;
import org.sdp.pearproject.service.*;
import org.sdp.pearproject.service.custom.*;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

/**
 * @ClassName: OrganizationServiceImpl
 * @Description:
 * @Author: SDP
 * @Date: 2022-07-04
 * @Version: 1.0
 * Table: pear_organization
 * Comment:
 * 组织表
 */
@Service
public class OrganizationServiceImpl extends OrganizationServiceCustomImpl implements OrganizationService {

    static {
        beanClassNameMap.put("organization", "organizationServiceImpl");
        listMethodNameMap.put("organization", "listOrganization");
        listMethodParameterClassNameMap.put("organization", "OrganizationQueryRequest");
        updateMethodNameMap.put("organization", "updateOrganization");
        updateMethodParameterClassNameMap.put("organization", "OrganizationUpdateRequest");
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Integer addOrganization(OrganizationAddRequest request) throws Exception {
        super.fixRequest("organization", "add", request);
        return super.addOrganization(request);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Integer updateOrganization(OrganizationUpdateRequest request) throws Exception {
        Organization record = null;
        record = organizationMapper.selectByPrimaryKey(request.getId());
        super.fixRequest("organization", "update", request, record);
        return super.updateOrganization(request);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Integer deleteOrganization(OrganizationDeleteRequest request) throws Exception {
        if (needCheckDeleteList(request)) {
            List<Organization> list = null;
            OrganizationExample example = new OrganizationExample();
            example.createCriteria().andIdIn(request.getIdList());
            list = organizationMapper.selectByExample(example);
            fixRequest("organization", "delete", request, list);
        } else {
            fixRequest("organization", "delete", request);
        }
        return super.deleteOrganization(request);
    }

    @Override
    public OrganizationQueryResponse queryOrganization(OrganizationQueryRequest request) throws Exception {
        super.checkNonNull(request.getId(), "id");
        OrganizationQueryResponse result = super.queryOrganization(request);
        checkResult("organization", "query", request, result);
        return result;
    }

    @Override
    public List<OrganizationQueryResponse> listOrganization(OrganizationQueryRequest request) throws Exception {
        List<OrganizationQueryResponse> list = super.listOrganization(request);
        checkResult("organization", "list", request, list);
        return list;
    }

    @Override
    public Integer countOrganization(OrganizationQueryRequest request) throws Exception {
        clearPageInfo(request);
        super.fixRequest("organization", "count", request);
        return super.countOrganization(request);
    }

    @Override
    public BaseStatResponse statOrganization(OrganizationQueryRequest request) throws Exception {
        clearPageInfo(request);
        super.fixRequest("organization", "stat", request);
        return super.statOrganization(request);
    }

}
